package by.parfen.game.listener;

import java.util.Date;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

//@WebListener
public class SessionListener implements HttpSessionListener {
	private int sessionCount = 0;

	@Override
	public void sessionCreated(HttpSessionEvent event) {
		synchronized (this) {
			sessionCount++;
		}
		System.out.println("Session Created: " + event.getSession().getId() + " on " + new Date());
		System.out.println("Total Sessions: " + sessionCount);
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		synchronized (this) {
			sessionCount--;
		}
		System.out.println("Session Destroyed: " + event.getSession().getId() + " on " + new Date());
		System.out.println("Total Sessions: " + sessionCount);
	}

}
